import axios from 'axios';

// OpenWeatherMap ApiKey & API_SERVER
const API_KEY = 'a131d7287a390edabf81c26ff023e59b';
const ROOT_URL = `http://api.openweathermap.org/data/2.5/forecast?appid=${API_KEY}`;

export const FETCH_WEATHER = 'FETCH_WEATHER';
export const REMOVE_CITY_FROM_WEATHER_LIST = 'REMOVE_CITY_FROM_WEATHER_LIST';

export function fetchWeather(city) {
  const url = `${ROOT_URL}&q=${city},cn`;
  const promise = axios.get(url);

  return {
    type: FETCH_WEATHER,
    payload: promise
  }
}

export function removeCity(city) {
  return {
    type: REMOVE_CITY_FROM_WEATHER_LIST,
    payload: city
  }
}
